--高压水枪
local gaoyashuiqiang = fk.CreateSkill {
    name = "mcdh_gaoyashuiqiang",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"


gaoyashuiqiang:addEffect(fk.CardEffectCancelledOut,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self)  then
            local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
            if use_event == nil then return end
            local is_from = false
            player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
                local use = e.data
                if use.responseToEvent == data then
                    if use.from == player then
                        is_from = true
                        event:setCostData(self,target)
                    else
                        event:setCostData(self,use.from)    
                    end
                    return true
                end
            end, use_event.id)
            return (is_from  and target ~= player) or (not is_from and target == player)
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local current = event:getCostData(self)
       return room:askToSkillInvoke(player,{skill_name= self.name,prompt="#mcdh_gaoyashuiqiang-invoke:"..current.id})
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local current = event:getCostData(self)
        local mark = player:getTableMark("mcdh_gaoyashuiqiang_distance-turn")
        mark[tostring(current.id)] = (mark[tostring(current.id)] or 0) + 1
        room:addPlayerMark(current, "@mcdh_gaoyashuiqiang-turn",1)
        room:setPlayerMark(player, "mcdh_gaoyashuiqiang_distance-turn",mark)
        if  not current:inMyAttackRange(player) or  not player:inMyAttackRange(current) then
            player:drawCards(1,self.name)
        end
    end
})

gaoyashuiqiang:addEffect('distance',{
    correct_func = function(self, from, to)
        local from_mark =  from:getTableMark("mcdh_gaoyashuiqiang_distance-turn")
        local to_mark = to:getTableMark("mcdh_gaoyashuiqiang_distance-turn")
        local temp = 0
        if from_mark[tostring(to.id)] then
            temp = temp + from_mark[tostring(to.id)]
        end
        if to_mark[tostring(from.id)] then
            temp = temp + to_mark[tostring(from.id)]
        end
        return temp

    end,
})


Fk:loadTranslationTable {
    ["mcdh_gaoyashuiqiang"] = "高压水炮",
    [":mcdh_gaoyashuiqiang"] = "当你抵消其他角色使用的牌后或其他角色抵消你使用的牌后，你可以令你与其本回合相互计算的距离+1，然后若你或其不在对方的攻击范围内，你摸一张牌。",
    ["@mcdh_gaoyashuiqiang-turn"] = "高压水炮",
    ["#mcdh_gaoyashuiqiang-invoke"] = "高压水炮：令你与 %src 本回合相互计算的距离+1，然后若你或其不在对方的攻击范围内，你摸一张牌。",
}

return gaoyashuiqiang